/*
 * queue.h
 *
 *  Created on: Aug 17, 2010
 *      Author: sdaniele
 */

#ifndef QUEUE_H_
#define QUEUE_H_


#include "tbb/task.h"
#include "tbb/tick_count.h"
#include "tbb/mutex.h"
#include "tbb/concurrent_vector.h"
#include "tbb/atomic.h"

namespace pilot {

	class process;

	class queue_t {
		public:
			queue_t(){}
			virtual ~queue_t(){}

		public:
			void push_backside(process* p){
				m_back.push_back(p);
			}

			void push_frontside(process* p){
				m_current.push_back(p);
			}

			void swap(){
				m_current.clear();
				m_current.swap(m_back);
			}

			process* operator[](size_t i){
				return m_current.at(i);
			}

			const process* operator[](size_t i) const{
				return m_current.at(i);
			}

			bool is_exhausted() const {
				return m_current.size()==0;
			}

			size_t size() const {
				return m_current.size();
			}

		private:
			tbb::concurrent_vector<process*> m_current;
			tbb::concurrent_vector<process*> m_back;
	};

}

#endif /* QUEUE_H_ */
